package com.googlecode.bip.xml.importe;

import java.sql.SQLException;
import javax.naming.NamingException;
import com.googlecode.bip.entity.IllegalValueException;

/**
 *
 * @author Claude CHOISNET
 */
public abstract class Commiter implements Commitable
{
    //private static final Logger logger = Logger.getLogger( Commiter.class );
    private SQLStatementCollection sqlCollection;


    public Commiter( SQLStatementCollection sqlCollection )
    {
        this.sqlCollection = sqlCollection;
    }

    /**
     * Must call {@link #performeCommit(String)}
     * @throws SQLException if any
     * @throws NamingException if any
     * @throws IllegalValueException if a value is not valid
     */
    @Override
    public abstract void commit()
        throws NamingException, SQLException, IllegalValueException;

//    /**
//     * Perform SQL update in database.
//     *
//     * @param sqlUpdate SQL to send to database.
//     * @throws NamingException if any
//     * @throws SQLException if any
//     */
//    protected final void __performeCommit( final String sqlUpdate )
//        throws NamingException, SQLException
//    {
//        logger.debug( "SQL: " + sqlUpdate );
//
//        Connection c = getConnection();
//        try {
//            ConnectionQuery connectionQuery = new ConnectionQuery( c ) ;
//
//            connectionQuery.doUpdate( sqlUpdate );
//            }
//        finally {
//            c.close();
//            }
//    }

    final
    protected void addSQLStatement( final String sqlUpdate )
    {
        sqlCollection.addSQLStatement( sqlUpdate );
    }

//    private Connection getConnection()
//        throws NamingException, SQLException
//    {
//        return MySQLDAOFactory.getConnection();
//    }

}
